package test;

import com.alibaba.excel.util.StringUtils;

import java.io.*;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Merge {

    public static void main(String[] args) throws Exception {
        File file1 = new File("/Users/hym/simu/study/try_practice/src/main/java/test/new2.txt");
        FileInputStream fileInputStream1 = new FileInputStream(file1);
        BufferedReader reader1 = new BufferedReader(new InputStreamReader(fileInputStream1));

        File file2 = new File("/Users/hym/simu/study/try_practice/src/main/java/test/workflow-role.txt");
        FileInputStream fileInputStream2 = new FileInputStream(file2);
        BufferedReader reader2 = new BufferedReader(new InputStreamReader(fileInputStream2));

        List<List<String>> s1 = new ArrayList<>();
        String temp = null;
        while ((temp = reader1.readLine()) != null) {
            String[] s = temp.split(" ");
            //时间
            String[] ts = new String[]{s[3], s[4], s[5], s[6]};
            String time = String.join(" ", ts);
            List<String> columns = new ArrayList<>();
            columns.add(time);
            String[] ds = new String[]{s[0], s[1], s[2]};
            columns.addAll(Stream.of(ds).collect(Collectors.toList()));
            s1.add(columns);
        }

        Map<String, List<String>> s2 = new HashMap<>();
        while ((temp = reader2.readLine()) != null) {
            String[] s = temp.split("\\|");
            List<String> processList = Stream.of(s).map(String::trim).collect(Collectors.toList());
            processList = processList.subList(1, processList.size());
            if (!StringUtils.isEmpty(processList.get(0))) {
                s2.put(processList.get(0), processList);
            }
        }

//        File result = new File("/Users/hym/simu/study/try_practice/src/main/java/test/result.txt");
//        FileOutputStream fileOutputStream = new FileOutputStream(result);
//        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fileOutputStream));
//
//        for (List<String> workflowRole : s1) {
//            String roleId = workflowRole.get(1);
//            if (!StringUtils.isEmpty(roleId)) {
//                List<String> role = s2.get(roleId);
//                if (Objects.nonNull(role)) {
//                    workflowRole.add(role.get(4));
//                    workflowRole.add(role.get(1));
//                }
//            }
//            writer.write(String.join(" ", workflowRole));
//            writer.newLine();
//        }
//
//        writer.close();
//        fileOutputStream.close();
//
//        reader2.close();
//        fileInputStream2.close();
//        reader1.close();
//        fileInputStream1.close();

        System.out.println(LocalDateTime.now().getYear());

    }

}
